package com.ai.zuochengyun.phase01.class03;

public class Code22_FullBinaryTree {

    public static void main(String[] args) {
        System.out.println(Math.pow(2, 3));
        System.out.println(Math.pow(3, 2));
    }

    public static boolean isFull(BinaryTreeNode head) {
        Info info = process(head);
        return info.height == (Math.pow(2, info.height) -1);
    }

    public static Info process(BinaryTreeNode head) {
        if (head == null) {
            return new Info(0, 0);
        }
        Info leftInfo = process(head.left);
        Info rightInfo = process(head.right);

        int height = Math.max(leftInfo.height, rightInfo.height) + 1;
        int nodes = leftInfo.nodes + rightInfo.nodes + 1;

        return new Info(nodes, height);
    }


    private static class Info {

        public int nodes;

        public int height;

        public Info(int nodes, int height) {
            this.nodes = nodes;
            this.height = height;
        }
    }
}
